<?php
/*
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
*/
require_once("../../../class2.php");
require("../library/admin/adminapi.php");

if (!$pref['upload_enabled'] || $pref['upload_class'] == 255) {
    header("location: ".e_BASE."index.php");
    exit;
}

require_once(e_ADMIN."auth.php");

if (!defined("USER_WIDTH")){ define("USER_WIDTH","width:97%"); }

if (!check_class($pref['upload_class'])) {
    $text = "<div style='text-align:center'>".lan_admin_upload_norights."</div>";
    $ns->tablerender(lan_global_error, $text);
    require_once(e_ADMIN."footer.php");
    exit;
}

if (isset($_POST['uploadcat']) || isset($_POST['uploadprod'])) {
    require_once(e_HANDLER."upload_handler.php");
    if ($_POST['uploadcat']) {
        //$uploaddir = str_replace("admin/", "", $shop_settings['path']."images/category/");
        $uploaded = process_uploaded_files("../images/category/", FALSE,
        array('file_types' => FALSE, 'file_mask' => 'jpg,gif,png', 
        'extra_file_types' => 'jpg,gif,png', 'overwrite' => TRUE));
    } elseif ($_POST['uploadprod']) {
        $uploaded = process_uploaded_files("../images/products/", FALSE,
        array('file_types' => FALSE, 'file_mask' => 'jpg,gif,png', 
        'extra_file_types' => 'jpg,gif,png', 'overwrite' => TRUE));
    }
    $file = $uploaded[0]['name'];
    $filetype = $uploaded[0]['type'];
    $filesize = $uploaded[0]['size'];
    $statuserr = $uploaded[0]['error'];
    $statusmsg = $uploaded[0]['message'];
    
    if ($statuserr == 0) {
        $file_time = time();
        $edata_fu = array("upload_file" => $file, "upload_size" => $filesize, "upload_image" => $image, "upload_time" => $file_time);
        $e_event->trigger("fileupload", $edata_fu);
    }
    $message .= "<br />".$statusmsg;
} 


//require_once(e_FILE."shortcode/batch/download_shortcodes.php");

$text = "<div style='text-align: center;'><br />
    <table style='".USER_WIDTH."' class='fborder'>
    <tr>
    <td style='text-align:center; font-size: 10pt;' colspan='2' class='forumheader3'>";

$text .= "<b>".lan_admin_upload_attention."</b><br /><br />".lan_admin_upload_accepted_files.":";


$a_filetypes = "jpg, png, gif";
$a_filetypes = explode(',', $a_filetypes);
foreach ($a_filetypes as $ftype) {
    $sa_filetypes[] = '.'.trim(str_replace('.', '', $ftype));
}
$allowed_filetypes = implode(' | ', $sa_filetypes);


$text .= " ".$allowed_filetypes."<br />".lan_admin_upload_be_removed."<br />".lan_admin_upload_max_filesize
.($pref['upload_maxfilesize'] ? $pref['upload_maxfilesize'] : ini_get('upload_max_filesize'))
."<br /><br />".lan_admin_upload_whitespace."</td></tr></table></div>";

$text2 = "<div style='text-align: center;'><br />
    <form enctype='multipart/form-data' method='post' action='".e_SELF."'>
    <table style='".USER_WIDTH."' class='fborder'>
    <tr>
    <td style='width:30%' class='forumheader3'>
    <span style='text-decoration:underline'>"
    .lan_admin_upload_category_picture."</span></td>
    <td style='width:70%' class='forumheader3'>
    <input class='tbox' style='width:90%' name='file_userfile[]' type='file' size='47' /></td>
    </tr>
    <tr>
    <td style='text-align:center' colspan='2' class='forumheader'>
    <input class='button' type='submit' name='uploadcat' value='".lan_admin_upload."' /></td>
    </tr>
    </table>
    </form>
    </div>";
    
$text3 = "<div style='text-align: center;'><br />
    <form enctype='multipart/form-data' method='post' action='".e_SELF."'>
    <table style='".USER_WIDTH."' class='fborder'>
    <tr>
    <td style='width:30%' class='forumheader3'>
    <span style='text-decoration:underline'>"
    .lan_admin_upload_product_picture."</span></td>
    <td style='width:70%' class='forumheader3'>
    <input class='tbox' style='width:90%' name='file_userfile[]' type='file' size='47' /></td>
    </tr>
    <tr>
    <td style='text-align:center' colspan='2' class='forumheader'>
    <input class='button' type='submit' name='uploadprod' value='".lan_admin_upload."' /></td>
    </tr>
    </table>
    </form>
    </div>";

$ns->tablerender("<center>".lan_admin_menu_upload."</center>", $text);
$ns->tablerender("<center>".lan_admin_upload_category."</center>", $text2);
$ns->tablerender("<center>".lan_admin_upload_product."</center>", $text3);
if (isset($message)) {
    $ns->tablerender("<center>".lan_global_status."</center>", "<div style=\"text-align:center\"><br /><b>".$message."</b><br /></div>");
}
require_once(e_ADMIN."footer.php");
